import routerlist from "./routerConfig";
import {Suspense} from "react" // 路由加载切换页面的loading
import {Routes,Route,BrowserRouter,Navigate} from "react-router-dom"
let RouterView = ()=>{
    let renderRoutes = (routerlist)=>{
           console.log(routerlist);
           return routerlist.map((item,index)=>{
               return item.path ? <Route key={index} path={item.path} element={<item.component></item.component>}>
                   {
                       item.children && renderRoutes(item.children)
                   }
               </Route>:
               <Route key={index} path={item.from} element={<Navigate to={item.to}></Navigate>}></Route>
           })
    }
    return <BrowserRouter>
             <Suspense fallback={<div>...laoding</div>}>
                <Routes>
                    {
                        renderRoutes(routerlist)
                    }
                </Routes>
             </Suspense>
          </BrowserRouter>
}
export default RouterView